package com.sne.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sne.common.entity.Result;
import com.sne.monitor.dto.MonitorTimeTaskLogDTO;
import com.sne.monitor.service.IMonitorTimeTaskLogService;
import com.sne.sys.dto.SysLogDTO;
import com.sne.sys.service.ISysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author fanghh
 * @date 2020/12/16
 */
@Validated
@RestController
@RequestMapping("/monitor/monitor-time-task-log")
@Api(tags = "定时任务")
public class MonitorTimeTaskLogController {

    @Autowired
    private IMonitorTimeTaskLogService service;

    @PreAuthorize("hasAuthority('monitor:time-task-log:page')")
    @ApiOperation(value = "日志列表")
    @PostMapping("/page")
    public Result page(Page page, @RequestBody MonitorTimeTaskLogDTO log) {
        return Result.success(service.findPage(page, log));
    }

    @PreAuthorize("hasAuthority('monitor:time-task-log:delete')")
    @ApiOperation(value = "删除日志")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return Result.success(service.removeById(id));
    }

    @PreAuthorize("hasAuthority('monitor:time-task-log:deleteIds')")
    @ApiOperation(value = "批量删除")
    @DeleteMapping("/deleteIds")
    public Result deleteIds(@RequestBody @Size(min = 1, message = "ids不能为空") List<Long> ids) {
        return Result.success(service.removeByIds(ids));
    }

    @PreAuthorize("hasAuthority('monitor:time-task-log:deleteAll')")
    @ApiOperation(value = "清空日志表")
    @DeleteMapping("/deleteAll")
    public Result deleteAll() {
        return Result.success(service.remove());
    }

    @ApiOperation(value = "根据id获取日志详情")
    @PostMapping("/find/{id}")
    public Result find(@PathVariable Long id){
        return Result.success(service.getById(id));
    }
}
